<template>
  <div>
    <div class="radios-box"  style="padding: 20px 0 10px 20px;">
      <el-radio-group v-model="tabIndex" @change="jumpInfo">
        <el-radio-button v-if="userPageAuth.userinfo" :label="1" name="1">用户管理表</el-radio-button>
        <el-radio-button v-if="userPageAuth.auth" :label="2" name="2">用户权限管理表</el-radio-button>
      </el-radio-group>
    </div>
    <div style="padding:10px 50px 30px">
      <el-row>
        <el-col :span="24">
          <noAuth :createFun="createFun">
            <el-row>
              <el-col :span="6"  v-if="activeId" style="margin: 20px 0">
                <el-button :disabled="isSelf" size="mini" @click="freeze(activeId)">冻结</el-button>
                <el-button :disabled="isSelf" size="mini" @click="unfreeze(activeId)">解冻</el-button>
                <el-button :disabled="isSelf" size="mini" @click="authUpdate">保存</el-button>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-card class="box-card" style="margin-top: 10px">
                  请选择账号 
                  <el-select style="margin:0 10px;" v-model="activeId" size="mini" placeholder="请选择" @change="selectUser">
                    <el-option
                      v-for="item in userList"
                      :key="item.id"
                      :label="item.username+'-'+item.account"
                      :value="item.id">
                    </el-option>
                  </el-select>
                  <div style="display: inline-block;" v-if="activeId">
                    <el-checkbox :disabled="!supperAdmin || isSelf" :true-label="1" :false-label="0" v-model="activeUser.isAdmin">管理员</el-checkbox>
                    <!-- <el-checkbox disabled :value="activeUser.supperAdmin">超级管理员</el-checkbox> -->
                    <span style="margin-left: 10px">账号状态：{{ activeUser.freeze ? '冻结' : '正常' }}</span>
                  </div>
                </el-card>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                  <el-form ref="authform" :disabled="isSelf">
                <el-card class="box-card" v-if="activeId" style="margin-top: 10px">
                  <div slot="header" class="clearfix">
                    <span>请选择页面及操作权限</span>
                    <div style="margin-top: 10px">
                      <el-checkbox :disabled="!supperAdmin" v-model="authObj.user.authorityAll">用户管理</el-checkbox>
                      <el-checkbox :disabled="!supperAdmin" v-model="authObj.userAuthority.authorityAll">用户权限管理</el-checkbox>
                      <el-checkbox v-model="authObj.systemConfig.authorityAll">系统配置管理</el-checkbox>
                      <el-checkbox v-model="authObj.vehicleMileageWarnConfig.authorityAll">车辆里程预警配置</el-checkbox>
                      <el-checkbox v-model="authObj.vehicleTimeWarnConfig.authorityAll">车辆时间预警配置</el-checkbox>
                      <el-checkbox v-model="authObj.empWarnConfig.authorityAll">人员预警配置</el-checkbox>
                    </div>
                  </div>
                  <div v-for="(item, i) in authObj" :key="i">
                    <el-row>
                      <div v-if="!item.oneAuth"  style="height:35px;line-height:35px">
                        <el-col :span="4">{{item.menuName}}</el-col>
                        <el-col :span="20">
                          <el-row>
                            <el-col :span="3"><el-checkbox v-if="i != 'warnDetails'" v-model="item.authorityAdd">增加/插入</el-checkbox><div class="place" v-else/></el-col>
                            <el-col :span="2"><el-checkbox v-if="i != 'warnDetails'" v-model="item.authorityDelete">删除</el-checkbox><div class="place" v-else/></el-col>
                            <el-col :span="2"><el-checkbox v-model="item.authorityUpdate">修改</el-checkbox></el-col>
                            <el-col :span="3"><el-checkbox v-model="item.authoritySearch">查询/搜索</el-checkbox></el-col>
                            <el-col :span="3"><el-checkbox v-model="item.authorityDown">Excel下载</el-checkbox></el-col>
                            <el-col :span="3"><el-checkbox v-if="i != 'warnDetails'" v-model="item.authorityImport">Excel上传</el-checkbox><div class="place" v-else/></el-col>
                            <el-col :span="3"><el-checkbox v-if="i != 'warnDetails'" v-model="item.authorityUpload">图片上传</el-checkbox><div class="place" v-else/></el-col>
                            <el-col :span="2"><el-button size="mini" @click="selectAll(i)">全选</el-button></el-col>
                            <el-col :span="3"><el-button size="mini" @click="cancelAll(i)">全取消</el-button></el-col>
                          </el-row>
                        </el-col>
                      </div>
                    </el-row>
                  </div>
                </el-card>
                  </el-form>
              </el-col>
            </el-row>
          </noAuth>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import adapter from './adapter'
import noAuth from '@/components/noAuth'
export default {
  name: 'auth',
  filters: {
    orderType(value) {
      if (value === 0) {
        return '补货'
      } else if (value === 1) {
        return '全部退货'
      } else if (value === 2) {
        return '部分退货'
      }
    }
  },
  components: {noAuth},
  data() {
    return {
      ...adapter.data,
      tabIndex: 2, // tab序号
    }
  },
  computed: {
    ...adapter.computed
  },
  created() {
    // 初始化
    this.initPage()
  },
  mounted() {
  },
  methods: {
    ...adapter.methods,
    createFun() {
      this.getAuth()
    },
    /**
     * 跳转车辆/员工信息
     */
    jumpInfo(tabIndex) {
      console.log(tabIndex)
      if (tabIndex == 1) {
        this.$router.push('userinfo')
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.place{
  width: 5px;
  height: 5px;
}
</style>

